<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改 DOM 树</title>
    <style>
        .alert{
            border: 1px solid #d6e0ce;
            border-radius: 4px;
            background-color: #dff0d8;
            padding: 15px;
        }
    </style>
</head>
<body>
    <ul id = "list">
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>
    <script>
        const last = document.createElement("li");
        last.innerHTML = "append";

        const list = document.getElementById("list");
        list.append(last);

        const first = last.cloneNode(true);
        first.textContent = "prepend";
        list.prepend(first);

        const alert = document.createElement("div");
        alert.textContent = "这是一个警告框! ";
        alert.className = "alert";
        list.before(alert);
        list.after(alert.cloneNode(true));

        const replace = first.cloneNode(true);
        replace.innerHTML = "replaceWith";
        const middle = list.children[Math.floor(list.children.length/2)];
        middle.replaceWith(replace);

        setTimeout(() => alert.remove(),2000);
        console.log("main");
    </script>
</body>
</html>